/* 布局 Layout */
import LayoutBase from '@/page/layout/base'
/* 系统监控 */
import monitor from './modules/monitor'

/* 文件管理 */
import file from './modules/file'
/* 权限管理 */
import authority from './modules/authority'
/* 权限管理 */
import email from './modules/email'
/* 系统管理 */
import system from './modules/system'
/* 个人资料 */
import person from './modules/person'
/* 客户模块 */
import customer from './modules/customer'
/* 产品模块 */
import product from './modules/product'
// 自动化模块
import automation from './modules/automation'
// 消息
import message from './modules/message'
// 反馈
import feedback from './modules/feedback'
// 错误日志管理
import error from './modules/error'
// 订单管理
import order from './modules/order'
// 海关数据
import ocean from './modules/ocean'
import store from "@/store";


const router = new VueRouter({
  routes: [
    {path: '/', redirect: '/login'},
    {
      path: '/login',
      name: 'login',
      meta: {
        title: '登录'
      },
      component: () => import(/* webpackChunkName: "login" */'@/views/user/login')
    },
    {
      path: '/home',
      component: LayoutBase,
      children: [
        {
          path: '/home',
          name: 'home',
          component: () => import(/* webpackChunkName: "lock" */'@/views/wel'),
          meta: {title: '首页'}
        }
      ]
    },
    ...monitor,
    ...file,
    ...authority,
    ...email,
    ...system,
    ...person,
    ...customer,
    ...product,
    ...automation,
    ...order,
    ...message,
    ...feedback,
    ...ocean,
    ...error,
    {
      path: '/404',
      name: '404',
      component: () => import(/* webpackChunkName: "404" */'@/components/error-page/404')
    },
    {path: '*', redirect: '/404'}
  ]
})

/******************路由跳转拦截器*******************************/

router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  // if (to.meta.title) {
  //   document.title = to.meta.title
  // }
  if (to.path != '/login') {
    if (store.state.user.token) {
      next();
    } else {
      store.commit('resetAllState')
      store.commit('set_isExpire',true);
      next('/login')
    }
  } else {
    next()
  }
})

export default router
